<div id="sidebar">
    <ul>
        <?php   /* Widgetized sidebar, if you have the plugin installed. */
                if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

        <li><h2>Feed</h2>
            <div class="feed"><a href="/feed"><img src="/wp-content/themes/PHPIDS/images/rss.gif" alt="Feed" /></a></div>            
        </li>

        <li><h2>Search</h2>
            <?php include (TEMPLATEPATH . '/searchform.php'); ?>
        </li>

        <?php if ( is_404() || is_category() || is_day() || is_month() ||
                    is_year() || is_search() || is_paged() ) {
        ?> <li>

        <?php /* If this is a 404 page */ if (is_404()) { ?>
        <?php /* If this is a category archive */ } elseif (is_category()) { ?>
        <p>You are currently browsing the archives for the <?php single_cat_title(''); ?> category.</p>

        <?php /* If this is a yearly archive */ } elseif (is_day()) { ?>
        <p>You are currently browsing the <a href="<?php bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives
        for the day <?php the_time('l, F jS, Y'); ?>.</p>

        <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
        <p>You are currently browsing the <a href="<?php bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives
        for <?php the_time('F, Y'); ?>.</p>

        <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
        <p>You are currently browsing the <a href="<?php bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives
        for the year <?php the_time('Y'); ?>.</p>

        <?php /* If this is a monthly archive */ } elseif (is_search()) { ?>
        <p>You have searched the <a href="<?php echo bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives
        for <strong>'<?php the_search_query(); ?>'</strong>. If you are unable to find anything in these search results, you can try one of these links.</p>

        <?php /* If this is a monthly archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
        <p>You are currently browsing the <a href="<?php echo bloginfo('url'); ?>/"><?php echo bloginfo('name'); ?></a> weblog archives.</p>

        <?php } ?>
            
        </li> <?php }?>

        <?php wp_list_pages('title_li=<h2>Pages</h2>' ); ?>

        <li><h2>Archives</h2>
            <ul>
            <?php wp_get_archives('type=monthly'); ?>
            </ul>
        </li>

        <?php
            if(file_exists('/home/phpids/common/log.txt') && is_readable('/home/phpids/common/log.txt')){
        ?>
        <li id="attacks"><h2>Recent Attacks</h2>
            <ul>
                <?php 
                    $attacks = file_get_contents('/home/phpids/common/log.txt');
                    $attacks = preg_split('/\n/', $attacks);
                    
                    $attacks = array_slice($attacks, count($attacks)-10, 10);
                    $attacks = array_reverse($attacks);
                    foreach($attacks as $item){
                        
                        preg_match_all('/(?:\d+\.\d+\.\d+\.\d+)|(?:"[^"]+")/s', $item, $matches);
                        
                        foreach($matches as $match){
                            if(!empty($match[0]) || !empty($match[1])){
                                echo '<li title="'.htmlentities(urldecode($match[1])).
                                        '"><strong><a href="http://www.ip2location.com/'.
                                            htmlentities(substr(urldecode($match[0]),0,15)).'" target="_blank">' .
                                                htmlentities(substr(urldecode($match[0]),0,15)) . '</a></strong> <span>' .
                                                    htmlentities(substr(urldecode($match[1]),1,18)) . '..</span></li>';    
                            }
                        }
                    }   
                    
                ?>
            </ul>
        <?php
            }
        ?>
        <?php endif; ?>
    </ul>
</div>